package com.sxit.tdf.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxit.tdf.server.entity.FileStorage;
import com.sxit.tdf.server.entity.bo.SimpleStoreBo;
import com.sxit.tdf.server.exception.TdfException;
import com.sxit.tdf.server.mapper.FileStorageMapper;
import com.sxit.tdf.server.service.IFileStorageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author 橙子高
 * @since 2022-03-06
 */
@Service
public class FileStorageServiceImpl extends ServiceImpl<FileStorageMapper, FileStorage>
    implements IFileStorageService {

  @Override
  public List<SimpleStoreBo> getStorageList() {
    return baseMapper.getStorageList();
  }

  @Override
  public Boolean deleteStoreInfoById(Integer id) {

    boolean isCan = baseMapper.canDeleteStore(id);
    if (isCan) {
      int i = baseMapper.deleteById(id);
      return i >= 1;
    } else {
      throw new TdfException("该存储室下面仍有文件存在");
    }
  }

  @Override
  public List<FileStorage> getStorageListByIds(List<Integer> integers) {
    return baseMapper.getStorageListByIds(integers);
  }
}
